/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 *
 */

import { TrackAPI } from '../../../common/trace/hvigor-trace-factory.js';
import { HvigorNodeDescriptor } from '../interface/hvigor-node-descriptor.js';

export class HvigorNodeDescriptorImpl implements HvigorNodeDescriptor {
  // 允许用户访问和修改
  public name: string;
  public srcPath: string;
  public extraOptions: Map<string, any> = new Map();

  // 只允许用户访问
  private childrenNode: HvigorNodeDescriptor[] | undefined;
  private rootNode: HvigorNodeDescriptor | undefined;

  constructor(name: string, srcPath: string, childrenNode: HvigorNodeDescriptor[] | undefined, rootNode: HvigorNodeDescriptor | undefined) {
    this.name = name;
    this.srcPath = srcPath;
    this.childrenNode = childrenNode;
    this.rootNode = rootNode;
  }

  @TrackAPI public getChildNode(): HvigorNodeDescriptor[] | undefined {
    return this.childrenNode;
  }

  @TrackAPI public getRootNode(): HvigorNodeDescriptor {
    return this.rootNode === undefined ? this : this.rootNode;
  }

  public setChildNode(childrenNode: HvigorNodeDescriptor[] | undefined): void {
    this.childrenNode = childrenNode;
  }
}
